﻿using LinqKit;
using Management.Auxiliary;
using System.Linq;
namespace Management.Core.SiliconCarbide
{
    public class SiliconCarbideManager:BaseManager<SiliconCarbide>
    {
        public Paging<SiliconCarbide> FindPageList(Paging<SiliconCarbide> pagingSiliconCarbide, int? siliconCarbideID, int? order)
        {
            //查询表达式
            var _where = PredicateBuilder.New<SiliconCarbide>(true);
            if (siliconCarbideID != null && siliconCarbideID > 0) _where = _where.And(u => u.SiliconCarbideID == siliconCarbideID);

            //排序
            OrderParam _orderParam;
            switch (order)
            {
                case 0://ID升序
                    _orderParam = new OrderParam() { PropertyName = "SiliconCarbideID", Method = OrderMethod.ASC };
                    break;
                case 1://ID降序
                    _orderParam = new OrderParam() { PropertyName = "SiliconCarbideID", Method = OrderMethod.DESC };
                    break;
                case 2://创建时间降序
                    _orderParam = new OrderParam() { PropertyName = "Created_at", Method = OrderMethod.ASC };
                    break;
                case 3://创建时间升序
                    _orderParam = new OrderParam() { PropertyName = "Created_at", Method = OrderMethod.DESC };
                    break;
                case 4://修改时间升序
                    _orderParam = new OrderParam() { PropertyName = "Updated_at", Method = OrderMethod.ASC };
                    break;
                case 5://修改时间降序
                    _orderParam = new OrderParam() { PropertyName = "Updated_at", Method = OrderMethod.DESC };
                    break;
                default://ID降序
                    _orderParam = new OrderParam() { PropertyName = "SiliconCarbideID", Method = OrderMethod.DESC };
                    break;
            }

            pagingSiliconCarbide.Items = Repository.FindPageList(pagingSiliconCarbide.PageSize, pagingSiliconCarbide.PageIndex, out pagingSiliconCarbide.TotalNumber, _where, _orderParam).ToList();
            return pagingSiliconCarbide;
        }
    }
}
